<template>
  <div>
    <PersonalCenterSidebar />
    <el-dialog
        v-model="dialogVisible"
        title="个人中心"
        width="400px"
        :custom-class="dialogCustomClass"
        :center="true"
        :show-close="false"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
    >
      <div class="dialog-content">
        <el-form ref="form" :model="formData" label-width="120px" class="personal-form">
          <el-form-item label="用户名">
            <el-input v-model="formData.userName" style="width: 80%" class="input-field" />
          </el-form-item>
          <el-form-item label="昵称">
            <el-input v-model="formData.nickName" style="width: 80%" class="input-field" />
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="formData.email" style="width: 80%" class="input-field" />
          </el-form-item>
          <el-form-item label="电话">
            <el-input v-model="formData.phone" class="input-field" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm" class="submit-button">提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";
import PersonalCenterSidebar from '@/views/PersonalCenterSidebar.vue';

export default {
  name: "PersonalCenter",
  components: {PersonalCenterSidebar},
  data() {
    return {
      dialogVisible: true,
      formData: {
        userName: '',
        nickName: '',
        email: '',
        phone: ''
      },
      dialogCustomClass: 'centered-dialog'
    };
  },
  methods: {
    submitForm() {
      const formDataToSend = this.formData;
      request.put("/user/updateUser", formDataToSend).then(res => {
        if (res.code === '0') {
          this.$message({
            type: "success",
            message: "更新成功"
          });
          this.dialogVisible = false;
        } else {
          this.$message({
            type: "error",
            message: res.msg
          });
        }
      });
    },
  },
  created() {
  }
};
</script>

<style scoped>
/* 对话框整体样式 */
.centered-dialog {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.3s ease-in-out;
}

.centered-dialog:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

/* 对话框内容样式 */
.dialog-content {
  width: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 表单样式 */
.personal-form {
  width: 100%;
  max-width: 360px;
  transition: all 0.3s ease-in-out;
}

.personal-form:hover {
  transform: translateY(-10px);
}

/* 输入框样式 */
.input-field .el-input__inner {
  border-radius: 20px;
  background-color: rgba(255, 255, 255, 0.9);
  border: none;
  padding: 10px 20px;
  transition: all 0.3s ease-in-out;
}

.input-field .el-input__inner:focus {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  background-color: rgba(255, 255, 255, 1);
}

/* 提交按钮样式 */
.submit-button {
  width: 100%;
  background-color: #ff5722;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 10px 20px;
  font-weight: bold;
  transition: all 0.3s ease-in-out;
  cursor: pointer;
}

.submit-button:hover {
  background-color: #e64a19;
  transform: scale(1.05);
}

/* 标签样式 */
.el-form-item__label {
  font-weight: bold;
  color: #333;
}

/* 对话框标题样式 */
.el-dialog__header {
  background-color: #ff5722;
  color: white;
  padding: 15px;
  text-align: center;
  border-bottom: 1px solid #ff7e5f;
  font-size: 20px;
  font-weight: bold;
}

/* 对话框关闭按钮样式 */
.el-dialog__headerbtn {
  color: white;
  font-size: 20px;
}

/* 对话框关闭按钮悬停样式 */
.el-dialog__headerbtn .el-dialog__close {
  color: white;
}

.el-dialog__headerbtn .el-dialog__close:hover {
  color: #ff7e5f;
}

/* 对话框内容区域样式 */
.el-dialog__body {
  padding: 20px;
  background-color: #f9f9f9;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}
</style>